/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.miracleteam.miracle.pages;

import com.miracleteam.miracle.entities.Khachhang;
import com.miracleteam.miracle.services.KhachHangService;
import com.miracleteam.miracle.services.servicesImpl.KhachHangServiceImpl;
import com.miracleteam.miracle.utils.MD5;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.annotations.SessionAttribute;

/**
 *
 * @author DangKhoa
 */
public class QuenMatKhau {
     @Property
        private String loginname;        
        @Property
        private String password;
	@Property
        private boolean remember_password=false;
        @SessionAttribute ("KhachHangDangNhap")
        private Khachhang KhachHang;
        @SessionAttribute ("DaDangNhap")
        private boolean DaDangNhap=false;
        
        @OnEvent
        public Object onSubmitLoginForm()
        {
           if(remember_password==true)
           {
               //Session session= ;
           }
                  
           Class nextPage=null;
           KhachHangService khSrv=new KhachHangServiceImpl();
           String passMD5=MD5.getMD5(password);
           Khachhang khDangNhap=khSrv.KiemTraDangNhap(loginname, passMD5);
           if(khDangNhap!=null)
           {
                setKhachHang(khDangNhap);
                setDaDangNhap(true);
                nextPage=Index.class;
           }
           else
           {
                nextPage=DangNhap.class;
           }
           return nextPage;
        }

    /**
     * @return the DaDangNhap
     */
    public boolean isDaDangNhap() {
        return DaDangNhap;
    }

    /**
     * @param DaDangNhap the DaDangNhap to set
     */
    public void setDaDangNhap(boolean DaDangNhap) {
        this.DaDangNhap = DaDangNhap;
    }

    /**
     * @return the KhachHang
     */
    public Khachhang getKhachHang() {
        return KhachHang;
    }

    /**
     * @param KhachHang the KhachHang to set
     */
    public void setKhachHang(Khachhang KhachHang) {
        this.KhachHang = KhachHang;
    }
}
